<?php
	include_once("inc/conn.php");
    include_once("inc/function.php");
    
    if(!isset($_SESSION['usersid'])) {
		echo "您还没登录或者链接超时，请先去<a href='/login.php'>登录</a>!";
		exit;
	}
	$act = intval($_GET['act']);
	//返回游戏记录
	GetRecordDetail($act);
	
    /* 返回游戏记录
    * 
    */
    function GetRecordDetail($act)
    {
		$no = intval($_GET['no']);

		
		$RetContent = "<div class='popup'>\r\n";
		//header
		$RetContent .= "\t<div class='popup-header'>\r\n";
		$RetContent .= "\t\t\t<h2>第{$no}期中奖名单</h2>\r\n";
		$RetContent .= "\t\t\t<a href='javascript:;' onclick='closerecord({$no})' title='关闭' class='close-link'>[关闭]</a>\r\n";
		$RetContent .= "\t\t\t<br clear='both' /> \r\n";
		$RetContent .= "\t</div>";
		//body
		$RetContent .= "\t<div class='popup-body'>\r\n";
		$RetContent .= GetTableContent($act,$no);
		$RetContent .= "\t</div>";
		
		echo $RetContent;
		exit;
    }
    
    /* 取号码表格
    *
    */
    function GetTableContent($act,$No)
    {
    	global $db;
    	$tabletz = GetGameTableName($act,'users_tz');
    	$tablegame = GetGameTableName($act,"game");
    	if($tabletz == "")
    		return "提交参数错误！";
    	//取押注情况
    	$sql = "SELECT tznum,tzpoints,points,hdpoints,zjpoints,zjpl FROM {$tabletz} WHERE uid = '{$_SESSION['usersid']}' AND NO = '{$No}'";
    	$result = $db->query($sql);
    	if($rs = $db->fetch_array($result))
    	{
			$arrtznum = explode("|",$rs['tznum']);
			$arrtzpoints = explode("|",$rs["tzpoints"]);
			$arrzjpoints = explode("|",$rs['zjpoints']);
			$hdpoints = $rs['hdpoints'];
			$points = $rs['points'];
			$zjpl=$rs['zjpl'];
			
    	}
    	else
    	{
			return "<p>很抱歉,无投注记录！</p>";
    	}
    	//取标准赔率
    	$reward_num_type = GetGameOddsType($act);
    		 
    	$sql = "SELECT GROUP_CONCAT(num SEPARATOR '|') AS strnum,GROUP_CONCAT(odds SEPARATOR '|') AS strodds FROM gameodds WHERE game_type = '{$reward_num_type}' ORDER BY num";
    	$result = $db->query($sql);
    	if($rs = $db->fetch_array($result))
    	{
    		$arrStdNums = explode("|",$rs['strnum']);
			$arrStdOdds = explode("|",$rs['strodds']);
    	}
    	else
    	{
			return "无法取得标准赔率";
    	}
    	//重新格式化押注情况
    	$arrNewtz = array();
    	$arrNewhdPoints = array();
    	foreach($arrStdNums as $num)
    	{
			$arrNewtz[$num] = 0;
			$arrNewhdPoints[$num] = 0;
    	}
    	for($i = 0; $i < count($arrtznum); $i++)
    	{
			$arrNewtz[$arrtznum[$i]] = $arrtzpoints[$i];
			$arrNewhdPoints[$arrtznum[$i]] = $arrzjpoints[$i];
    	}
    	//取开奖赔率
    	$sql = "SELECT zjpl,kgtime FROM {$tablegame} WHERE id = {$No}";
    	$result = $db->query($sql);
    	if($rs = $db->fetch_array($result))
    	{
			$arrRwardOdds = explode("|",$rs['zjpl']);
			$kgtime = $rs['kgtime'];
    	}
    	else
    	{
			return "无法取得开奖赔率";
    	}
    	//填表
		$divTable ="<div class='table'>";
		$divTable .= "\t<table class='table_list table table-hover table-striped table-bordered' >\r\n";
		$divTable .= "\t<tbody>\r\n";
		$divTable .= "\t\t<tr><td colspan='5'>第{$No}期投注详细结果</td></tr>\r\n";
		$divTable .= "\t\t<tr><td colspan='5' class='please'>开奖时间:{$kgtime} 投注:<span>". Trans($points) ."</span> 获得:<span>". Trans($hdpoints) ."</span></td></tr>\r\n";
		
		$divTable .= "\t\t<tr>\r\n";
		$divTable .= "\t\t\t<th width='80'>号码</th>\r\n";
		$divTable .= "\t\t\t<th width='100'>标准赔率</th>\r\n";
		$divTable .= "\t\t\t<th width='100'>开奖赔率</th>\r\n";
		$divTable .= "\t\t\t<th width='160'>投注数量</th>\r\n";
		$divTable .= "\t\t\t<th width='160'>获得数量</th>\r\n";
		$divTable .= "\t\t</tr>\r\n";
		for($i = 0; $i < count($arrStdNums);$i++)
    	{
			$divTable .= "\t\t<tr>\r\n";
			if($act == 16) //pk龙虎
			{
				if($arrStdNums[$i] == 1)
					$divTable .= "\t\t\t<td><li class='finalbig'>龙</li></td>\r\n";
				else
					$divTable .= "\t\t\t<td><li class='finalbig'>虎</li></td>\r\n";
			}
			else if($act == 11 || $act == 12 || $act == 13 || $act == 21)
			{
				$NumberNameStr = "";
				switch($arrStdNums[$i])
				{
					case 1:
						$NumberNameStr = "豹";
						break;
					case 2:
						$NumberNameStr = "对";
						break;
					case 3:
						$NumberNameStr = "顺";
						break;
					case 4:
						$NumberNameStr = "半";
						break;
					case 5:
						$NumberNameStr = "杂";
						break;
					default:
						break;
				}
				$divTable .= "\t\t\t<td><li class='finalbig'>{$NumberNameStr}</li></td>\r\n";
			}
			else
			{
				$divTable .= "\t\t\t<td><li class='finalbig'>{$arrStdNums[$i]}</li></td>\r\n";
			}
			
			$divTable .= "\t\t\t<td>{$arrStdOdds[$i]}</td>\r\n";
			if($arrNewhdPoints[$arrStdNums[$i]]>0 && doubleval($zjpl)>0) {
				$divTable .= "\t\t\t<td>".sprintf('%.4f',$zjpl)."</td>\r\n";
			}else{
				$divTable .= "\t\t\t<td>{$arrRwardOdds[$i]}</td>\r\n";
			}
			$divTable .= "\t\t\t<td class='please'>". Trans($arrNewtz[$arrStdNums[$i]]) ."</td>\r\n";
			$divTable .= "\t\t\t<td class='please'>". Trans($arrNewhdPoints[$arrStdNums[$i]]) ."</td>\r\n";
			$divTable .= "\t\n</tr>\r\n";
    	}
		$divTable .= "\t</tbody>\r\n";
		$divTable .= "\t</table>\r\n";
		$divTable .= "</div>";
		return $divTable;
    }
    
    
